package com.itheima.mvc.controller;

import com.itheima.mvc.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class ParamController {

    //http://localhost/requestParam1?name=itheima&age=14
    //get post可以
    //？传参 普通传参
    @RequestMapping("requestParam1")
    public String requestParam1(@RequestParam("name") String name1,
                                @RequestParam("age") Integer age1){
        System.out.println("requestParams1: name="+name1+",age="+age1);
        return "/success.jsp";
    }
    @RequestMapping("requestParam2")
    public String requestParam2(User user){
        System.out.println("requestParams2: name="+user.getName()+",age="+user.getAge());
        return "/success.jsp";
    }


    @RequestMapping("requestParam3")
    public String requestParam3(User user, Integer age){
        //参数名称一致的情况下，都会赋值
        System.out.println("requestParams3: name="+user.getName()+",age="+user.getAge());
        System.out.println("方法中的age="+age);
        return "/success.jsp";
    }
    // http://localhost/requestParam4?name=itheima&age=14&address.province=beijing
    @RequestMapping("requestParam4")
    public String requestParam4(User user){
        //参数名称一致的情况下，都会赋值
        System.out.println("requestParams4: "+user);
        return "/success.jsp";
    }
    // http://localhost/requestParam5?name=itheima&age=14&address.province=beijing&addresses[0].province=bj&addresses[1].province=tj
    @RequestMapping("requestParam5")
    public String requestParam5(User user){
        //参数名称一致的情况下，都会赋值
        System.out.println("requestParams5: "+user);
        return "/success.jsp";
    }
    //复杂传参的时候 post传参 json数据
    //http://localhost/requestParam6?addressMap['bj'].province=beijing
    @RequestMapping("requestParam6")
    public String requestParam6(User user){
        //参数名称一致的情况下，都会赋值
        System.out.println("requestParams6: "+user);
        return "/success.jsp";
    }

    //http://localhost/requestParam7?name=zhangsan&name=lisi
    @RequestMapping("requestParam7")
    public String requestParam7(String[] name){
        //参数名称一致的情况下，都会赋值
        for (String s : name) {
            System.out.println("requestParams7 name= "+s);
        }
        return "/success.jsp";
    }
    //http://localhost/requestParam8?name=zhangsan&name=lisi
    @RequestMapping("requestParam8")
    public String requestParam8(@RequestParam("name") List<String> name){
        //参数名称一致的情况下，都会赋值
        for (String s : name) {
            System.out.println("requestParams8 name= "+s);
        }
        return "/success.jsp";
    }

    //1. @RequestParam  用于接收get形式请求的参数
    //2. @RequestParam  如果是传文件 也用这个注解post


//    @RequestMapping(value = "requestParam9",method = RequestMethod.POST)
    @GetMapping("requestParam9")
    public String requestParam9(){
        //参数名称一致的情况下，都会赋值
        System.out.println("requestParams9");
        return "/success.jsp";
    }

}
